//
//  HXTConsumInfoVC.m
//  掌上宏力
//
//  Created by admin on 2017/5/22.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "HXTConsumInfoVC.h"
#import "CardConsumModel.h"
#import "CardConsumCell.h"
#import "HXTConsumViewModel.h"

@interface HXTConsumInfoVC ()

@property (nonatomic,strong) HXTConsumViewModel *viewModel;

@property (nonatomic,strong) NSMutableArray *datasArray;

@end

@implementation HXTConsumInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"消费明细";
}

-(void)getDatasArray{
    [self getDatasArray:^(NSString *page, GetDatas handler) {
        _viewModel = [[HXTConsumViewModel alloc] init];
        [_viewModel getHXTConsumWithPage:page success:^{
            if (self.currentPage == 1) {
                _datasArray = [NSMutableArray arrayWithArray:_viewModel.datasArray];
            }else{
                [_datasArray addObjectsFromArray:_viewModel.datasArray];

            }
            handler(_viewModel.datasArray);

        }];
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    CardConsumModel *consum = _datasArray[section];
    NSString *dateStr = consum.date;
    return [dateStr substringToIndex:dateStr.length-10];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CardConsumCell *cell = [CardConsumCell cellWithTableView:tableView];
    CardConsumModel *consum = _datasArray[indexPath.section];
    cell.consum = consum;
    return cell;
}

@end
